﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinesys.Entities;
using Chinesys.DataModel;

namespace Chinesys.Domain.DataMapper
{
    public static class OrderDetailDataMapper
    {
        public static OrderDetailEntity OrderDetailFromRowToEntity(OrderDetail row)
        {
            OrderDetailEntity entity;
            if (row != null)
            {
                entity = new OrderDetailEntity()
                {
                    Id = row.Id,
                    OrderId = row.OrderId,
                    Quantity = row.Quantity,
                    UnitPrice = row.UnitPrice,
                    CurrentState = RowState.Original
                };
            }
            else
                entity = null;

            return entity;
        }

        public static OrderDetail OrderDetailFromEntityToRow(OrderDetailEntity entity)
        {
            OrderDetail row;

            if (entity != null)
            {
                row = new OrderDetail()
                {
                    Id = entity.Id,
                    OrderId = entity.OrderId,
                    Quantity = entity.Quantity,
                    UnitPrice = entity.UnitPrice
                };
            }
            else
                row = null;

            return row;
        }
    }
}
